package com.ych.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * Created with IntelliJ IDEA.
 * Author: Usopp.tsui
 * Date: 2020/12/10
 * Time: 13:54
 * Description:跨域配置
 */
@Configuration
public class CorsConfig implements WebMvcConfigurer {

    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")
                .allowedOrigins("*")
                .allowCredentials(true)
                .allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS")
                .maxAge(3600);
    }

    /**
     * 添加文件上传路径配置
     * 上传到指定路径后，直接访问ip:spingboot端口/img/**.png
     * 例如：http://localhost:8080/img/head.png
     * @param registry
     */
//    @Override
//    public void addResourceHandlers(ResourceHandlerRegistry registry) {
////        registry.addResourceHandler("/img/**")//配置访问路径
////                .addResourceLocations("file:/static/");//文件上传到的位置
//        registry.addResourceHandler("/file/**")//配置访问路径
//                .addResourceLocations("file:D:/data/");//文件上传到的位置
//    }
}